package com.lagou.component;

import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class EmailHelper {

    @Value("${email.host}")
    private String host;
    @Value("${email.port}")
    private Integer port;
    @Value("${email.from}")
    private String from;
    @Value("${email.user}")
    private String user;
    @Value("${email.pass}")
    private String pass;

    public void sendMail(String emailAddress,String subject,String bodyPreview){
        MailAccount account =this.buildAccount();
        String send = MailUtil.send(account,emailAddress, subject, bodyPreview, false);
    }

    private MailAccount buildAccount() {
        MailAccount account = new MailAccount();
        account.setHost(host);
        account.setPort(port);
        account.setAuth(true);
        account.setFrom(from);
        account.setUser(user);
        account.setPass(pass);
        return account;
    }
}
